package ru.amse.tsyganov.jumleditor.commands;

import ru.amse.tsyganov.jumleditor.model.common.State;
import ru.amse.tsyganov.jumleditor.view.common.StateView;

/*package*/ class ResizeStateCommand extends MoveStateCommand {
	
	private final int oldWidth;
	
	private final int oldHeight;
	
	private final int newWidth;
	
	private final int newHeight;
	
	public ResizeStateCommand(StateView<? extends State> resizingState, 
			int moveToX, int moveToY, int newWidth, int newHeight) {
		
		super(resizingState, moveToX, moveToY, false);
		
		if (newWidth < 0 || newHeight < 0) {
			throw new IllegalArgumentException();
		}
		
		oldWidth = resizingState.getWidth();
		oldHeight = resizingState.getHeight();
		
		this.newWidth = newWidth;
		this.newHeight = newHeight;
		
		if (oldHeight == newHeight && oldWidth == newWidth) {
			throw new IllegalArgumentException();
		}
	}

	@Override
	public void execute() {
		getMovingState().setWidth(newWidth);
		getMovingState().setHeight(newHeight);
		super.execute();
	}

	@Override
	public void unexecute() {
		getMovingState().setWidth(oldWidth);
		getMovingState().setHeight(oldHeight);
		super.unexecute();
	}

}
